package com.example.cloudmusicserve.controller;

import com.example.cloudmusicserve.util.HttpClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpMethod;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @description: Music
 * @author: xiaoyuan
 * @time: 2023/5/24
 */

@RestController
@Api(tags = "音乐接口")
public class Music {
    //定义全局变量string
    private String u = "http://127.0.0.1:3000";

    // 注入Httpclient
    @Resource
    HttpClient httpClient;

    //获取轮播接口
    @ApiOperation("获取轮播接口")
    @GetMapping("/banner")
    public String getBannerMusic(){
        String url = u+"/banner";
        HttpMethod httpMethod = HttpMethod.GET;
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        return  httpClient.client(url, httpMethod,params);
    }

    //获取热门歌手的接口
    @ApiOperation("获取热门歌手的接口")
    @GetMapping("/top/artists")
    public String getHotArtists(){
        String url = u+"/top/artists";
        HttpMethod httpMethod = HttpMethod.GET;
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        return  httpClient.client(url, httpMethod,params);
    }

    //获取最新音乐
    @ApiOperation("获取最新音乐")
    @GetMapping("/personalized/newsong")
    public String getNewSongs(){
        String url = u+"/personalized/newsong";
        HttpMethod httpMethod = HttpMethod.GET;
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        return  httpClient.client(url, httpMethod,params);
    }

    //通过ID来获取音乐
    @ApiOperation("通过ID来获取音乐")
    @GetMapping("/song/url")
    public String getByIdMusic(@RequestParam("id") String id){
        String url = u+"/song/url?id="+id;
        HttpMethod httpMethod = HttpMethod.GET;
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        return  httpClient.client(url, httpMethod,params);
    }

    //通过ID来获取是否是可以用的音乐
    @ApiOperation("通过ID来获取是否是可以用的音乐")
    @GetMapping("/check/music")
    public String getcheckMusic(@RequestParam("id") String id){
        String url = u+"/check/music?id="+id;
        HttpMethod httpMethod = HttpMethod.GET;
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        return  httpClient.client(url, httpMethod,params);
    }

    //通过id来获取歌手详情信息
    @ApiOperation("通过id来获取歌手详情信息")
    @GetMapping("/artist/detail")
    public String getSingerDetail(@RequestParam("id") String id){
        String url = u+"/artist/detail?id="+id;
        HttpMethod httpMethod = HttpMethod.GET;
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        return  httpClient.client(url, httpMethod,params);
    }

    //通过id获取歌手的热门歌曲
    @ApiOperation("通过id获取歌手的热门歌曲")
    @GetMapping("/artist/top/song")
    public String getSingerHotMusic(@RequestParam("id") String id){
        String url = u+"/artist/top/song?id="+id;
        HttpMethod httpMethod = HttpMethod.GET;
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        return  httpClient.client(url, httpMethod,params);
    }

    //通过ID来获取歌手详情
    @ApiOperation("通过ID来获取歌手详情")
    @GetMapping("/song/detail")
    public String getMusicDetail(@RequestParam("ids") String id){
        String url = u+"/song/detail?ids="+id;
        HttpMethod httpMethod = HttpMethod.GET;
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        return  httpClient.client(url, httpMethod,params);
    }

    //通过id来获取歌词
    @ApiOperation("通过id来获取歌词")
    @GetMapping("/lyric")
    public String getMusicLyric(@RequestParam("id") String id){
        String url = u+"/lyric?id="+id;
        HttpMethod httpMethod = HttpMethod.GET;
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        return  httpClient.client(url, httpMethod,params);
    }

    //获取为你推荐类型
    @ApiOperation("获取为你推荐类型")
    @GetMapping("/dj/category/recommend")
    public String getRecommendOfYourCategory(){
        String url = u+"/dj/category/recommend";
        HttpMethod httpMethod = HttpMethod.GET;
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        return  httpClient.client(url, httpMethod,params);
    }

    //获取推荐类型
    @ApiOperation("获取推荐类型")
    @GetMapping("/dj/category/excludehot")
    public String getRecommendCategory(){
        String url = u+"/dj/category/excludehot";
        HttpMethod httpMethod = HttpMethod.GET;
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        return  httpClient.client(url, httpMethod,params);
    }

    //通过关键字来获取音乐
    @ApiOperation("通过关键字来获取音乐")
    @GetMapping("/search")
    public String getKeywordsMusic(@RequestParam("keywords")String keywords){
        String url = u+"/search?keywords="+keywords;
        HttpMethod httpMethod = HttpMethod.GET;
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        return  httpClient.client(url, httpMethod,params);
    }

}
